package bs;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception
    {
        System.out.println("==服务端启动==");
        //1.创建一个TCP服务端Socket对象
        ServerSocket ss = new ServerSocket(8080);
        //2.调用accept方法，阻塞等待客户端连接，一旦有客户端连接，就返回一个Socket对象，用于和客户端进行数据通信
        try {
            while(true){
                Socket socket = ss.accept();
                System.out.println("一个客户端上线了！" + socket.getInetAddress().getHostAddress());
                new ServerReader(socket).start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
